<?php
namespace app\mouth\controller;
use app\mouth\common\Api;
use app\mouth\model\CircleIndexModel;
use think\Db;
/**
 * 圈子首页控制器
 * Class CircleIndexApi
 * @package app\mouth\controller
 */
class CircleIndexApi extends Api{
    /**
     * 首页
     * openid
     * userid
     * portrait  头像
     * gender    性别
     * nickname    性别
     */

     public function index(){

            $userid = CircleIndexModel::position($this->openid);
            if ($userid == false){
                $userid = CircleIndexModel::personalInformation(input('openid'),input('portrait'),input('gender'),input('nickname'));
            }
            $date = CircleIndexModel::allContent($userid);
            return $this->jsons('40006','获取成功',$date);
        }
    /**
     * 帖子详情
     * u_id  帖子u_id
     */
        public function postDetails(){
            $comment['u_id'] = input('u_id');
            $comment['portrait'] = input('portrait');
            $comment['content'] = input('content');
            $comment['picture'] = input('picture');
            $comment['comment'] = CircleIndexModel::postComments(input('u_id'));
            return $this->jsons('40006','获取成功',$comment);
        }
    /**
     * 点赞  1   fabulous
     * 喜欢  2  like
     */
        public function spot(){
            $test = (int)input('spot');
            $value = CircleIndexModel::giveFabulous(input('p_id'),$this->quanzi_id['id'],input('i_id'),$this->portrait,$this->nickname,$test);
            if ($value === false){
                return $this->jsons('40003','请勿重复点击',[]);
            }
            return $this->jsons('40006','成功',[]);
        }

    /**
     * 关注表
     */
        public function follow(){
//            var_dump(input());die;
            $information = CircleIndexModel::focusOnPeople(input('main_id'),$this->quanzi_id['id'],input('portrait'),input('nickname'));
            if ($information === false ){
                return $this->jsons('40003','请勿重复点击',[]);
            }
            return $this->jsons('40006','关注成功',[]);
        }
    /**
     * 取消关注
     */
    public function qufollow(){
       $qu = CircleIndexModel::qufollow(input('main_id'),$this->quanzi_id['id']);
        $this->add($qu);
    }
    /**
     * 评论
     */
        public function comment(){
            $date = CircleIndexModel::myComments(input());
            if ($date == true){
                return $this->jsons('40006','评论',[]);
            }
            return $this->jsons('40003',$date,[]);
        }
}